package com.debao.common.exception;

public class AesException extends Exception {

    public static final int OK = 0;
    public static final int VALIDATE_SIGNATURE_ERROR = -40001;
    public static final int PARSE_XML_ERROR = -40002;
    public static final int COMPUTE_SIGNATURE_ERROR = -40003;
    public static final int ILLEGAL_AES_KEY = -40004;
    public static final int VALIDATE_APPID_ERROR = -40005;
    public static final int ENCRYPT_AES_ERROR = -40006;
    public static final int DECRYPT_AES_ERROR = -40007;
    public static final int ILLEGAL_BUFFER = -40008;
    public static final int ENCODE_BASE64_ERROR = -40009;
    public static final int DECODE_BASE64_ERROR = -40010;
    public static final int GEN_RETURN_XML_ERROR = -40011;


    private int code;
    private static String getMessage(int code) {
        switch (code) {
            case VALIDATE_SIGNATURE_ERROR:
                return "签名验证错误";
            case PARSE_XML_ERROR:
                return "XML解析失败";
            case COMPUTE_SIGNATURE_ERROR:
                return "签名计算错误";
            case ILLEGAL_AES_KEY:
                return "AES密钥非法";
            case VALIDATE_APPID_ERROR:
                return "appid验证失败";
            case ENCRYPT_AES_ERROR:
                return "AES加密失败";
            case DECRYPT_AES_ERROR:
                return "AES解密失败";
            case ILLEGAL_BUFFER:
                return "解密后得到的buffer非法";
            case ENCODE_BASE64_ERROR:
                return "base64加密错误";
            case DECODE_BASE64_ERROR:
                return "base64解密错误";
            case GEN_RETURN_XML_ERROR:
                return "生成返回的XML失败";
            default:
                return null; // cannot be
        }
    }

    public int getCode() {
        return code;
    }

    public AesException(int code) {
        super(getMessage(code));
        this.code = code;
    }
}

